import react from 'react'
import './App.css';
import 'antd/dist/antd.css';

import store from './store';
import { change_input_value, submit_value, delete_value } from './store/actionCreate'
import APPUI from './APPui'
import RouteLink from "./routeLink";
class App extends react.Component {
  constructor(props) {
    super(props)
    this.state = store.getState()
    this.ev_inputChange = this.ev_inputChange.bind(this)
    this.ev_submit = this.ev_submit.bind(this)
    this.ev_delete = this.ev_delete.bind(this)
    this.ev_subscribeStore = this.ev_subscribeStore.bind(this)
    store.subscribe(this.ev_subscribeStore)
  }
  render() {
    return (
      <div>
        <RouteLink></RouteLink>
        <APPUI
          inpVal={this.state.inpVal}
          list={this.state.list}
          ev_inputChange={this.ev_inputChange}
          ev_submit={this.ev_submit}
          ev_delete={this.ev_delete}
        ></APPUI>
      </div>
    )
  }
  //修改输入框的值
  ev_inputChange(e) {
    const action = change_input_value(e.target.value)
    store.dispatch(action)
  }
  //订阅
  ev_subscribeStore() {
    this.setState(store.getState())
  }
  //添加
  ev_submit() {
    const action = submit_value()
    store.dispatch(action)
  }
  //删除
  ev_delete(idx) {
    const action = delete_value(idx)
    store.dispatch(action)
  }
}

export default App;
